(function($) {
    function init(target) {
        $(target).addClass('progressbar');
        return $(target);
    }
    $.fn.progressbar = function(options, param) {
        if (typeof options == 'string') {
            var method = $.fn.progressbar.methods[options];
            if (method) {
                return method(this, param);
            }
        }

        options = options || {};
        return this.each(function() {
            var state = $.data(this, 'progressbar');
            if (state) {
                $.extend(state.options, options);
            } else {
                state = $.data(this, 'progressbar', {
                    options: $.extend({}, fn.progressbar.defaults, $.fn.progressbar.parseOptions(this), options),
                    bar: init(this)
                })
            }
        })
    }
    $.fn.progressbar.methods = {
        options: function(jq) {
            return $.data(jq[0], 'progressbar').options;
        },
        getValue: function(jq) {
            return $.data(jq[0], 'progressbar').options.value;
        }
    }

    $.fn.progressbar.parseOptions = function(target) {
        return $.extend({}, $.parser.parseOptions(target, ['width', 'height', 'text', { value: 'number' }]));
    }

    $.fn.progressbar.defaults = {
        width: 'auto',
        height: 22,
        value: 0,
        text: '{value}%',
        onChange: function(newValue, oldValue) {}
    }

})(jQuery)